<?php
	require_once dirname(BASEPATH) . '/application/models/local/data/_init_model.php';
	
	class mod_cafe_type extends _init_model
	{
		public $CAF_T_ID;
		public $CAF_T_TITLE;
		
		function __construct()
		{
			parent::__construct();
		
			$this->tableName = "cafe_type";
		}
		
		function get_cafe_type(){
			$this->db->select(array('CAF_T_ID', 'CAF_T_TITLE'));
			$query = $this->db->get($this->tableName);			
			return $query->result_array();
		}
		function get_cafe_type_for_dropdownlist(){
			$result = $this->get_cafe_type();
			
			$return = array();
			foreach ($result as $row){
				$return[$row['CAF_T_ID']] = $row['CAF_T_TITLE'];
			}
			return $return;
		}
		function get_cafe_type_title($id){
			$this->db->select('CAF_T_TITLE');
			$this->db->where('CAF_T_ID', $id);
			$query = $this->db->get($this->tableName);
			
			if ($query->num_rows() > 0)
				return $query->row(0)->CAF_T_TITLE;
			else
				return null;
		}
		function get_cafe_type_list($cafe_id=null){
			$this->db->select(array('CAF_T_ID', 'CAF_T_TITLE'));
			$query = $this->db->get($this->tableName);			
			$return = $query->result_array();
			
			if (count($return) > 0){
				
				// get list of cafe type
				$this->load->model('local/data/cafe/mod_cafe_type_list');
				$type_array = $this->mod_cafe_type_list->get_typelist_of_cafe($cafe_id);
					
				for ($i=0; $i<count($return); $i++){					
					if (in_array($return[$i]['CAF_T_ID'], $type_array))
						$return[$i]['SET'] = true;
					else
						$return[$i]['SET'] = false;
				}
			}
			
			return $return;
		}
	}
?>